//
//  TeachActionsView.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/9/30.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "TeachActionsView.h"

@implementation TeachActionsView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

#pragma mark ==========创建视图==========
- (void)createSubView{//115*145 55 62.5
    NSArray *imageArr = [NSArray arrayWithObjects:@"TeachActionsViewOneImage",@"TeachActionsViewTwoImage",@"TeachActionsViewThreeImage",@"TeachActionsViewFourImage", nil];
    NSArray *titleArr = [NSArray arrayWithObjects:@"学员管理",@"培训管理",@"模拟考试",@"考试管理", nil];
    for (int i=0; i<4; i++) {//button层级高优先显示button
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.frame = CGRectMake(0, 0, 115*SCALEUNIT, 145*SCALEUNIT);
        btn.center = CGPointMake(112.5*SCALEUNIT+175*SCALEUNIT*i, self.frame.size.height*0.5);
        btn.tag = 1000+i;
        [self initButton:btn WithImgName:[imageArr objectAtIndex:i] WithTitle:[titleArr objectAtIndex:i]];
        [btn addTarget:self action:@selector(btnOpen:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
    }
}
-(void)initButton:(UIButton*)btn WithImgName:(NSString *)imgName WithTitle:(NSString *)title{
    UIImageView *imagView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imgName]];
    [btn addSubview:imagView];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = title;
    titleLabel.textColor = [UIColor colorWithHexString:@"#686868"];
    titleLabel.font = [UIFont systemFontOfSize:LoginFont-4];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [btn addSubview:titleLabel];
    
    [imagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(btn).with.offset(5*SCALEUNIT);
        make.centerX.mas_equalTo(btn);
        make.size.mas_equalTo(CGSizeMake(105*SCALEUNIT, 105*SCALEUNIT));
    }];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(btn);
        make.top.mas_equalTo(imagView.mas_bottom).with.offset(5*SCALEUNIT);
    }];
}

#pragma mark ==========按钮点击==========
- (void)btnOpen:(UIButton *)btn{
    if ([self.delegate respondsToSelector:@selector(teachActionsViewDelegateWithTag:)]) {
        [self.delegate teachActionsViewDelegateWithTag:btn.tag-1000];
    }
}

@end
